import {LabLayout} from "../../enums/StoreEnums";

const LabBodyModule = {
    state: {
        classes: {}
    },
    mutations: {
        [LabLayout.Mutations.SET_CLASSNAME_BY_POSITION]: (state, payload) => {
            if (!state.classes[payload.className]) {
                state.classes[payload.position] = []
            } else {
                state.classes[payload.position].push(payload.className)
            }
        }
    },
    actions: {
        [LabLayout.Actions.ADD_BODY_CLASSNAME]: (ctx, className) => document.body.classList.add(className),
        [LabLayout.Actions.REMOVE_BODY_CLASSNAME]: (ctx, className) => document.body.classList.remove(className),
        [LabLayout.Actions.ADD_BODY_ATTRIBUTE]: (ctx, attr) => document.body.setAttribute(attr.qulifiedName, attr.value),
        [LabLayout.Actions.REMOVE_BODY_ATTRIBUTE]: (ctx, attr) => document.body.removeAttribute(attr.qulifiedName),
        [LabLayout.Actions.ADD_CLASSNAME]: ({commit}, payload) => commit(LabLayout.Mutations.SET_CLASSNAME_BY_POSITION, payload)
    },
    getters: {
        classes: (state) => (position) => {
            if (typeof position !== "undefined") {
                return state.classes[position];
            }
            return state.classes;
        }
    }
}
export default LabBodyModule